package collectionsDemo;

public class Demo2 {
	public static void main(String[] args){
		Foo foo = new Foo(100);
		Foo foo2 = new Foo(50);
		System.out.println(foo.compareTo(foo2));
		//字符串当中，默认重写了compareTo方法
		String s1 = "aaaaa";
		String s2 = "bbb";
		String s3 = "c";
		String s4 = "c";
		System.out.println(s1.compareTo(s2));
		System.out.println(s3.compareTo(s2));
		System.out.println(s3.compareTo(s4));
	}
}

class Foo implements Comparable{
//比较必须是同一个类型
	int num;
	public Foo(int num) {
		// TODO Auto-generated constructor stub
		this.num=num;
	}
	//原则：如果返回值是正数，this比obj大
	@Override
	public int compareTo(Object obj) {
		// TODO Auto-generated method stub
		Foo foo1 = (Foo)obj;
		return this.num-foo1.num;
	}
	
}
